package com.sunhao.application;

import androidx.appcompat.app.AppCompatActivity;

import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity6 extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_result;
    private TimePicker time_picker;
    private Button btn_confirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main6);

        tv_result = findViewById(R.id.tv_result);
        time_picker = findViewById(R.id.time_picker);
        btn_confirm = findViewById(R.id.btn_confirm);
        btn_confirm.setOnClickListener(this);

        Button btn_select = findViewById(R.id.btn_slelect);
        btn_select.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.btn_confirm:
                //从日期选择器中拿到日期
                String desc = String.format("您选择的日期是%d时%d分",time_picker.getHour(),time_picker.getMinute());
                tv_result.setText(desc);
                break;

            case R.id.btn_slelect:
                TimePickerDialog timePickerDialog = new TimePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog, new TimePickerDialog.OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        String desc = String.format("您选择的日期是%d时%d分",hourOfDay,minute);
                        tv_result.setText(desc);
                    }
                },12,50,true);
                timePickerDialog.show();

                break;
        }
    }


}